﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SchemaMonitor.html
{
	[Serializable]
	public class CPostList : List<CTimeline>
	{
		//Constructor
		public CPostList() { }
		public CPostList(int c) : base(c) { }
		public CPostList(IEnumerable<CTimeline> list) : base(list) { }


		//Index
		public CPostList GetByType(ETimeline t)
		{
			CPostList list = null;
			if (!Index.TryGetValue(t, out list))
			{
				list = new CPostList(0);
				Index.Add(t, list);
			}
			return list;
		}
		private Dictionary<ETimeline, CPostList> _index;
		public Dictionary<ETimeline, CPostList> Index
		{
			get
			{
				if (null == _index)
				{
					var dict = new Dictionary<ETimeline, CPostList>();
					foreach (var i in this)
					{
						CPostList temp = null;
						if (!dict.TryGetValue(i.Type_, out temp))
						{
							temp = new CPostList();
							dict.Add(i.Type_, temp);
						}
						temp.Add(i);
					}
					_index = dict;
				}
				return _index;
			}
		}
	}
}
